package example.day10.英雄联盟;

import java.util.Random;

/**
 * @author 涛哥
 * @nick_name "deep as the sea"
 * @contact qq:657270652 wx:doit_edu
 * @site www.doitedu.cn
 * @date 2021-03-15
 * @desc 剑圣
 */
public class SwordMan extends Hero{

    /**
     * 击杀小兵的方法
     * @return
     */
    @Override
    public int killSoldier() {
        Random rd = new Random();
        int killed = rd.nextInt(5)+ 1;

        // 更新击杀小兵数
        this.killedSodiers += killed;

        // 更新金币数
        updateCoin("soldier",killed);

        // 更新积分
        updatePoint("soldier",killed);

        return killed;
    }

    @Override
    public int killHero() {
        return 0;
    }

    /**
     * 更新金币
     */
    private void updateCoin(String killedType,int number){

        if("hero".equals(killedType)){
            this.coin += 5*number;
        }

        if("soldier".equals(killedType)){
            this.coin += 1*number;
        }

        if("monster".equals(killedType)){
            this.coin += 2*number;
        }
    }

    /**
     * 更新积分
     */
    private void updatePoint(String killedType,int number){
        if("hero".equals(killedType)){
            this.point += 10*number;
        }

        if("soldier".equals(killedType)){
            this.point += 2*number;
        }

        if("monster".equals(killedType)){
            this.point += 5*number;
        }

        // 更新等级
        updateGrade();
    }

    private void updateGrade(){
        // 1-100   1
        // 101-200 2
        int tmp = 0;
        if(this.point% 100 == 0){
            tmp = this.point/100;
        }else{
            tmp = this.point/100 +1;
        }

        this.grade = tmp>18?tmp:18;
    }

}
